package com.hl.qzzpbackend.controller;
import com.hl.qzzpbackend.common.BaseResponse;
import com.hl.qzzpbackend.common.ResultUtils;
import com.hl.qzzpbackend.model.entity.User;
import com.hl.qzzpbackend.service.FileService;
import com.hl.qzzpbackend.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


/**
 * 文件 接口
 *
 * @author helong
 */
@Slf4j
@Api(tags = "文件接口")
@RestController
@RequestMapping("/file")
public class FileController {

    @Resource
    private UserService userService;

    @Resource
    private FileService fileService;

    // 上传公司logo
    @ApiOperation(value = "上传公司logo")
    @RequestMapping(value = "/upload/logo", method = RequestMethod.POST)
    public BaseResponse<String> uploadLogo(@RequestPart("file") MultipartFile multipartFile, HttpServletRequest request) {
        if(log.isInfoEnabled()){
            log.info("上传公司logo：{}", multipartFile);
        }
        User loginUser = userService.getLoginUser(request);
        String url  = fileService.uploadLogo(multipartFile,loginUser);
        return ResultUtils.success(url);
    }

    // 上传简历附件
    @ApiOperation(value = "上传简历附件")
    @RequestMapping(value = "/upload/resume", method = RequestMethod.POST)
    public BaseResponse<Boolean> uploadResume(@RequestPart("file") MultipartFile multipartFile, HttpServletRequest request) {
        if(log.isInfoEnabled()){
            log.info("上传简历附件：{}", multipartFile);
        }
        User loginUser = userService.getLoginUser(request);
        boolean result  = fileService.uploadResume(multipartFile,loginUser);
        return ResultUtils.success(result);
    }


}
